﻿$(function(){
	/* Evita mecher na página ao clicar
 num link com # */
		$('a').click(function(event){
			if($(this).attr('href') == '#') {
				event.preventDefault();
			}
		});
        
         $("#searchform select").jQSelect();
            $("#footerheading .search select").jQSelect();
        // Footer Social animation.
		$('#footercontent .support img').animate({ 'opacity' : 0.5 });
		$('#footercontent .support img').mouseenter(function() {
			$(this).animate({ 'opacity' : 1 });
		});
		$('#footercontent .support img').mouseleave(function() {
			$(this).animate({ 'opacity' : 0.5 });
		});
    // Navigation
		$('#navigation ul').append('<div class="bottomcorners"> </div>');
		$('#navigation ul').find('li:last').css({ 'border-bottom' : '0 none' , 'padding-bottom' : '0'  })
		$('#navigation h3').mouseover(function() {
			$('#navigation h3').removeClass('hovered');
			$(this).addClass('hovered');
			$('#navigation ul').hide();
			var  pos = $(this).get(0);
			var child = $(this).next();
			$(child).show();
			$(child).css({ 'left' : pos.offsetLeft });
		});
		$('#navigation').mouseleave(function(){
			$('#navigation ul').hide();
			$('#navigation h3').removeClass('hovered');
		});

        $('.steps ul li:last-child').css({ 'border-right' : '0 none' });
        
        
	
    
    
    filters = [];
    
	$("#gibson #recomend #recomendwrap li:lt(4)").css("display", "block");
	$("#gibson #newsletterButtonOK").attr("value", "Cadastrar");
	$('#productslidercontainer .prateleira li .filter').each(function(){
    
       var marca = $(this).find('li:first').text();
    
        $(this).html(  marca );
        $(this).attr({ 'data-filter' :  marca });
        $(this).parent().removeClass().addClass(marca);
        
        filters.push( marca );
        
    });
    
    
    
    collection = $('#productslidercontainer .prateleira ul').clone();
    items = $(collection).clone();
	totalOfItens = $(collection).find('li').size();
	totalOfPages = Math.ceil(totalOfItens / 3);
    productIndex = 1;
    
    
    
	$("#navigation-steps").append("<div class='navitems'><a href='javascript:void(0)' class='prev'>Retornar</a> <span>" + productIndex + " de " + totalOfItens + "</span> <a href='javascript:void(0)' class='next'>Avançar</a></div>");
	$("#navigation-steps .navitems").css("margin-left", (($("#navigation-steps .navitems").width()/2) * (-1)));

    $('#navigation-steps .prev').click(function(){
    
        productIndex--;
        
        if ( productIndex  <= 0 ) {
        
            productIndex = totalOfItens;
        
        }
        
        $('#navigation-steps .navitems span').html(productIndex + " de " + totalOfItens);
    
    });
    
    $('#navigation-steps .next').click(function(){
        
        productIndex++;
        
        if ( productIndex  >= totalOfItens ) {
        
            productIndex = 1;
        
        }

        $('#navigation-steps .navitems span').html(productIndex + " de " + totalOfItens);
    
    });
    
    $('#navigation-steps .prev').live('click',function(){
    
        productIndex--;
        
        if ( productIndex  <= 0 ) {
        
            productIndex = totalOfItens;
        
        }
        
        $('#navigation-steps .navitems span').html(productIndex + " de " + totalOfItens);
    
    });
    
    $('#navigation-steps .next').live('click',function(){
        
        productIndex++;
        
        if ( productIndex  >= totalOfItens ) {
        
            productIndex = 1;
        
        }

        $('#navigation-steps .navitems span').html(productIndex + " de " + totalOfItens);
    
    });
    
    
    /*$('#productslidewrapper #productslidercontainer .prateleira').bxSlider({
      displaySlideQty: 3,
      moveSlideQty: 1,
      prevSelector: '#navigation-steps .prev',
      nextSelector: '#navigation-steps .next'
    });*/
    
    $('#productslidewrapper #productslidercontainer .prateleira').jCarouselLite({ visible: 3,btnNext: "#navigation-steps .next", btnPrev: "#navigation-steps .prev"});
    
     
   
    
    
    
    
    $( filters ).each(function(i){
        
        var str = filters[i];
        
        if ( $('#gibson-products-nav ul li.' + str.replace(' ','.') ).size() == 0 ){
            
            $('#gibson-products-nav ul').append('<li class="' + str + '"><a href="javascript:void(0)">' + str + '</a></li>');
        
        }
    
    });
    
    $('#gibson-products-nav ul li').live('click',function() {
    
        $('#gibson-products-nav ul li').removeClass('active');
       
    
        if ( $(this).is('.all') ){
        
              items = $(collection).clone();
              $('#productslidercontainer .prateleira ul').empty();
                $('#productslidercontainer .prateleira ul').append($(items));
        }else{
    
        var classe = $(this).attr('class').replace(' ' , '.');
        
        items = $(collection).clone();
        $('#productslidercontainer .prateleira ul').empty();
        $('#productslidercontainer .prateleira ul').append( $(items).find('.' + classe) );
  
       
        }
        
        totalOfItens = $('#productslidercontainer .prateleira ul li').size();
        totalOfPages = Math.ceil(totalOfItens / 3);
        productIndex = 1;
        
        
        
        $("#navigation-steps").empty().append("<div class='navitems'><a href='javascript:void(0)' class='prev'>Retornar</a> <span>" + productIndex + " de " + totalOfItens + "</span> <a href='javascript:void(0)' class='next'>Avançar</a></div>");
        $("#navigation-steps .navitems").css("margin-left", (($("#navigation-steps .navitems").width()/2) * (-1)));

        
         $(this).addClass('active');
         
           
        $('#productslidewrapper #productslidercontainer .prateleira').jCarouselLite({ visible: 3,btnNext: "#navigation-steps .next", btnPrev: "#navigation-steps .prev"});
    
      
         
         
    });
    
    //Filtros
       
	//$('#marcas-up').jCarouselLite({circular: true, auto: 1, visible: 5,  auto: 1200, animation : 'slow', initCallback: mycarousel_initCallback, mouseWheel: true, btnNext: "#seta-dir", btnPrev: "#seta-esq"});
	//$('#gibson #recomend #recomendwrap .prateleira ul').jCarouselLite({circular: true, visible: 4,  auto: 1200, animation : 'slow', btnNext: "#btn_nav_next", btnPrev: "#btn_nav_prev"});
	
    /*var delay = window.setTimeout(function() {
    
        $('#gibson #recomend #recomendwrap .prateleira').jCarouselLite({circular: true, visible: 4, animation : 'slow', btnNext: "#btn_nav_next", btnPrev: "#btn_nav_prev"});
    
    },3500);*/
    
    /*$('#gibson #recomend #recomendwrap .prateleira ul').bxSlider({
      displaySlideQty: 4,
      moveSlideQty: 1,
      prevSelector: '#btn_nav_prev',
      nextSelector: '#btn_nav_next'
    });*/
    
    
    $('#btn_nav_prev, #btn_nav_next').css({ 'visibility' : 'hidden' } );
    
    
    
    
    
    // Paginacao
    listsize = Math.round( $('#gibson #recomend #recomendwrap .n4colunas ul:not(ul ul)').size() / 6 );
            
    i = 1;
    while ( i <= listsize ) {
        $('#hotsite-navigation ul').append('<li class="page-number">' + ( i ) + '</li>');
        i++;
    }
    
    $('#hotsite-navigation ul li:first').addClass('pgCurrent');
    
    $('.resultado-busca .n4colunas ul').hide(); 
  
    $('#recomendwrap .n4colunas ul:not(ul ul):eq(0)').show();
    $('#recomendwrap .n4colunas ul:not(ul ul):eq(1)').show();
    $('#recomendwrap .n4colunas ul:not(ul ul):eq(2)').show();
    $('#recomendwrap .n4colunas ul:not(ul ul):eq(3)').show();
    //$('#recomendwrap .n4colunas ul:not(ul ul):eq(4)').show();
    //$('#recomendwrap .n4colunas ul:not(ul ul):eq(5)').show();

    $('#hotsite-navigation ul li').click(function() {
    
        var openindex = $(this).index('#hotsite-navigation ul li');
        
        $('#recomendwrap .n4colunas ul:not(ul ul)').hide();
        $('#recomendwrap .n4colunas ul:not(ul ul):eq(' + (openindex * 4 ) + ')').show();
        $('#recomendwrap .n4colunas ul:not(ul ul):eq(' + ((openindex * 4 ) + 1) + ')').show();
        $('#recomendwrap .n4colunas ul:not(ul ul):eq(' + ((openindex * 4 ) + 2 ) + ')').show();
        $('#recomendwrap .n4colunas ul:not(ul ul):eq(' + ((openindex * 4 ) + 3 ) + ')').show();
        //$('.resultado-busca .n4colunas ul:eq(' + ((openindex * 4 ) + 4 ) + ')').show();
        //$('.resultado-busca .n4colunas ul:eq(' + ((openindex * 4 ) + 5 ) + ')').show();
        
        $('#hotsite-navigation ul li').removeClass('pgCurrent');
        $('#hotsite-navigation ul li:eq(' + openindex + ')').addClass('pgCurrent');
    });
            
    
    
});
